package com.xiaoq.system.endpoint;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.annotations.Api;

@Api(tags = "app下载")
@Controller
@RequestMapping("/api/download_app")
public class AppDownloadEndpoint {
	private static final Logger LOG = LoggerFactory.getLogger(AppDownloadEndpoint.class);

	@GetMapping("/download")
	private void contentSharing(HttpServletRequest request, HttpServletResponse response) {
		String agent = request.getHeader("user-agent");
		if (agent.contains("Android")) {

			try {
				response.sendRedirect("https://sj.qq.com/myapp/detail.htm?apkName=com.xiaoq");
			} catch (IOException e) {
				LOG.error(e.getMessage(), e);
			}

		} else if (agent.contains("iPhone") || agent.contains("iPod") || agent.contains("iPad")) { // 通过微信进入此界面时，由于苹果市场并没有提供在浏览器中打开的提示

			try {
				response.sendRedirect("https://itunes.apple.com/cn/app/id1391444371");
			} catch (IOException e) {
				LOG.error(e.getMessage(), e);
			}

		}
	}

}
